package org.zjx.model.prop;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Map;

/**
 * 道具实例 - 玩家实际拥有的道具实例
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ItemInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    private int id;           // 实例唯一ID
    private String name;       //道具名称
    private String playerId;     // 所属玩家ID
    private int templateId;      // 关联的模板ID
    private int slotId;         // 所在槽位ID
    private int stack;          //堆叠数量


    // 道具属性
    private int durability;      // 耐久度/剩余次数/剩余量
    private boolean durabilityEmptyDelete; //durability <=0 是否销毁
    private boolean bound;       // 是否绑定
    private Map<String, Object> attributes; // 额外属性

    //道具识别
    private boolean gather;      //是否匹配过模板

    /**
     * 减少耐久度
     */
    public boolean reduceDurability(int amount) {
        this.durability = Math.max(0, this.durability - amount);
        return this.durability == 0;
    }
}